﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OutdoorLib.BaseEntity.Agency;

public partial class GroupList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (this.Page.Request["__EVENTTARGET"] == "RowGrid")
        {
            OnRowClick(this.Page.Request["__EVENTARGUMENT"]);
        }      


        if (!IsPostBack)
        {
            lvGroupList.DataSource = Source;
            DataBind();
        }
            

    }

    private  Group.EGroupType GroupType 
    {
        get{
            if (Request["GroupType"] == OutdoorLib.BaseEntity.Agency.Group.EGroupType.SurfaceGroup.ToString())
                return Group.EGroupType.SurfaceGroup;
            return Group.EGroupType.ClientGroup;
            }
    }

    private List<Group>  Source
    {
        get { return AppEnvironment.CurrentAgency.GetGroupItems(GroupType).ToList<Group>(); } 
    }

    protected string TagName 
    {
        get { return Request.QueryString[GlobalConstants.qTagName]; }
    }

    protected void btnAddRecord_Click(object sender, EventArgs e)
    {

        string sUrl = AppEnvironment.PageNavigator.GetNewObjectUrlCommand(TGroupList.GetPageKey(GroupType),
                                                                           TagName,
                                                                            null);
        Response.Redirect(sUrl);

    }

    protected string GetRowClick(string RowID)
    {
        string[] s = { "RowGrid", RowID };
        string ss = string.Format("CallServer('{0}', '{1}');", s);
        return ss;
    }
    
    protected void OnRowClick(string RowId)
    {
        string sUrl = AppEnvironment.PageNavigator.GetEditObjectUrlCommand(TGroupList.GetPageKey(GroupType),
                                                                            RowId,
                                                                            TagName,
                                                                             null);
        Response.Redirect(sUrl);

    }

}
